<?php
use \PsiFramework\Classes\Util\UI\Printer;
use \PsiFramework\Classes\Util\UI\HTML;
use \PsiFramework\Classes\Util\Log\Logger;

$object = $response->getAttribute("object");
$objectType = $response->getAttribute("objectType");
$columns = $response->getAttribute("columns");

$id = '' ;
if (!is_null($object)) $id = $object->getId();
echo HTML::link("Edit", "action=CMS.Edit&type=".$objectType."&id=".$id);
echo " | " ;
echo HTML::link("Retour", "action=CMS.List&type=".$objectType);
echo " | " ;
?>
<a href="javascript:if (
        confirm('Etes-vous sûr de vouloir supprimer l\'entrée ?')
    ) {
        window.location='<?php Printer::display(HTML::linkHref("action=CMS.Delete&type=".$objectType."&id=".$id)); ?>';
    }"
>
    Supprimer
</a>
<ul>
    <?php 
    foreach ($columns as $name=>$sqlColumn) {
        if ($sqlColumn->display) {
            $method = $sqlColumn->getter ;
            $element = $object->$method();
            $string = "" ;
            if (!is_null($element)) {
                if (is_array($element)) {
                    foreach ($element as $item) {
                        if ($string != "") $string .= "\n" ;
                        if (is_string($item)) $string .= $item;
                        else $string .= $item->toString();
                    }
                } else {
                    if (
                        $sqlColumn->type == "bool" ||
                        $sqlColumn->type == "boolean"
                    ) {
                        if ($element) $string = "true" ;
                        else $string = "false" ;
                    } else if ($sqlColumn->isPrimitive()) {

                        $string = $element;
                    }
                    else $string = $element->toString();
                }
            }
     ?>
    <li>
        <span class="object-title">
            <?php Printer::display($sqlColumn->name . " : "); ?>
        </span>
        <span class="object-value">
            <?php Printer::display($string); ?>
        </span>
    </li>
    <?php
        }
    }
    ?>
</ul>
<?php
echo HTML::link("Edit", "action=CMS.Edit&type=".$objectType."&id=".$id);
echo " | " ;
echo HTML::link("Retour", "action=CMS.List&type=".$objectType);
echo " | " ;
?>
<a href="javascript:if (
        confirm('Etes-vous sûr de vouloir supprimer l\'entrée ?')
    ) {
        window.location='<?php Printer::display(HTML::linkHref("action=CMS.Delete&type=".$objectType."&id=".$id)); ?>';
    }"
>
    Supprimer
</a>